load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")
load("//build:STRINGER.bzl", "stringer")

proto_library(
    name = "catpb_proto",
    srcs = [
        "catalog.proto",
        "enum.proto",
        "function.proto",
        "privilege.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
)

go_proto_library(
    name = "catpb_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb",
    proto = ":catpb_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/sql/sem/catid",  # keep
        "@com_github_gogo_protobuf//gogoproto",
    ],
)

go_library(
    name = "catpb",
    srcs = [
        "catalog.go",
        "default_privilege.go",
        "doc.go",
        "expression.go",
        "function.go",
        "job_id.go",
        "multiregion.go",
        "privilege.go",
        ":gen-privilegedescversion-stringer",  # keep
    ],
    embed = [":catpb_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/keys",
        "//pkg/security/username",
        "//pkg/sql/privilege",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/catid",
        "@com_github_cockroachdb_errors//:errors",
    ],
)

go_test(
    name = "catpb_test",
    srcs = ["privilege_test.go"],
    deps = [
        ":catpb",
        "//pkg/keys",
        "//pkg/security/username",
        "//pkg/sql/catalog/bootstrap",
        "//pkg/sql/privilege",
        "//pkg/sql/sem/catid",
        "//pkg/testutils",
        "//pkg/util/leaktest",
    ],
)

stringer(
    name = "gen-privilegedescversion-stringer",
    src = "privilege.go",
    typ = "PrivilegeDescVersion",
)

disallowed_imports_test(
    src = "catpb",
    disallowed_list = [
        "//pkg/sql/sem/tree",
    ],
)
